<?php
/**
* @package Pages-and-Items (com_pi_pages_and_items)
* @version 1.5.7
* @copyright Copyright (C) 2006-2010 Carsten Engel. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author http://www.pages-and-items.com
*/

//no direct access
if(!defined('_VALID_MOS') && !defined('_JEXEC')){
	die('Restricted access');
}

//globals
global $pageId, $type, $task, $sub_task, $item_id, $item_type, $my;

//get vars
if(defined('_JEXEC')){
	//joomla 1.5	
	$task = JRequest::getVar('task', '');
	$sub_task = JRequest::getVar('sub_task', '');
	$pageId = intval(JRequest::getVar('pageId', ''));
	$item_id = intval(JRequest::getVar('item_id', ''));
	$item_type = JRequest::getVar('item_type', '');
}else{
	//joomla 1.0.x
	$task = mosGetParam( $_REQUEST, 'task', '' );
	$sub_task = mosGetParam( $_REQUEST, 'sub_task', '' );
	$pageId = intval(mosGetParam( $_REQUEST, 'pageId', '' ));
	$item_id = intval(mosGetParam( $_REQUEST, 'item_id', '' ));
	$item_type = mosGetParam( $_REQUEST, 'item_type', '' );
}

//include class
require_once(dirname(__FILE__).'/class.php');
$class_pi = new class_pi();

//set default page
if(!$task){	
	//get name of first menu
	$temp_menus = explode(',',$class_pi->pi_config['menus']);	
	$menutype = explode(';',$temp_menus[0]);	
	$url = 'index2.php?option=com_pi_pages_and_items&task=root&menutype='.$menutype[0];
	if(defined('_JEXEC')){
		//joomla 1.5
		$mainframe->redirect($url);
	}else{
		//joomla 1.0.x
		mosRedirect($url);
	}	
}

//do function
$task_functions_array = array('image_file_delete','image_upload_process','page_save','page_trash','root_save','item_save','item_move_save','page_move_save','cancel','config_save','config_itemtype_save','download_delete','download_upload_process','download_access_save','download_reset','config_custom_itemtype_save','config_custom_itemtype_field_save','custom_itemtype_fields_delete','config_custom_itemtype_delete','ajax_update_cit_item','ajax_make_menu_alias_unique');
if (in_array($task, $task_functions_array)){
	$class_pi->$task();	
}

//get admin page
$task_admin_page_array = array('item_move_select','page_browser','page_browser_popup','image_upload','image_select','page_move_select','root','page','item','config','config_itemtype','download_upload','download_select','item_copy_select','config_custom_itemtype','config_custom_itemtype_field','render_items_by_custom_itemtype','render_menu_alias_unique','instance_select');
if(in_array($task, $task_admin_page_array)){
	$class_pi->set_title();	
	$frontend = 0;
	require_once(dirname(__FILE__).'/admin/'.$task.'.php');
}

//get plugin function or adminpage
$item_type_array = array('googlevideo', 'image_gallery', 'module_position', 'php', 'youtube', 'text', 'html', 'other_item');
if($task=='plugin' && in_array($item_type, $item_type_array)){
	$class_pi->set_title();		
	require_once(dirname(__FILE__).'/../../../'.$class_pi->plugin_dir.'/pages_and_items/itemtypes/'.$item_type.'/'.$item_type.'_admin.php');
}

// ADD MS NOVEMBER 2010
$plugin = JRequest::getVar('plugin', '');
//get field_plugin function or adminpage
$field_type_array = array('code','folder_image','item_hits','item_read_more_link','item_read_more_url','link','youtube');
if($task=='field_plugin'  && in_array($item_type, $plugin)){
	$class_pi->set_title();
	require_once(dirname(__FILE__).'/../../../'.$class_pi->plugin_dir.'/pages_and_items/fieldtypes/'.$plugin.'/'.$plugin.'_admin.php');
}
// END ADD MS NOVEMBER 2010
?>